package com.beiding.workordersystem.main.utils;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.SimpleType;

import java.util.Map;

public class Json {

    private static ObjectMapper objectMapper = new ObjectMapper();

    public static String stringify(Object object) {
        try {
            return objectMapper.writeValueAsString(object);
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }

    public static <T> T parse(String json, Class<T> type) {
        try {
            return objectMapper.readValue(json, SimpleType.constructUnsafe(type));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static Map parseToMap(String json) {
        return (Map) JSON.parse(json);
    }


}
